package demo.email;

import act.controller.annotation.TemplateContext;
import act.event.On;
import act.job.Cron;
import act.job.Every;
import act.mail.Mailer;
import act.util.Async;
import org.osgl.mvc.annotation.PostAction;
import org.osgl.storage.ISObject;

import java.io.File;

@Mailer
@TemplateContext("/mail")
public class PostOffice extends Mailer.Util {

    public static final String EVENT_USER_SIGN_UP = "sign-up";

    @On(EVENT_USER_SIGN_UP)
    public void sendWelcomeLetter(User user) {
        to(user.email);
        subject("welcome to Fantasy Service");
        // uncomment the following to send without template
        //content("Hi %s, Welcome to Fantasy Service", user.firstName);
        send(user);
    }

    @PostAction("/send-attachment")
    public void sendAttachment(String to) {
        to(to);
        subject("See attachment");
        content("See attachment");
        File file = new File("/tmp/x.txt");
        attach(file);
        send();
    }

    //@Every("5s")
    @Mailer("notification")
    public void sendEmailPeriodically() {
        subject("notification");
        content("Hello ActFramework!");
        send();
    }

}
